fix(nix): parse Nix versions without a patch component#2866
Conversation
Newer Nix releases report versions like "2.33pre20251107_479b6b73" that omit the patch component. The version regexp required major.minor.patch, so parsing failed and the version was left empty, causing devbox to abort with: Error: Devbox requires nix of version >= 2.12.0. Your version is . Make the patch component optional in versionRegexp and coerce patchless / prerelease Nix versions into valid semvers before comparing in Info.AtLeast. Fixes #2766
There was a problem hiding this comment.
Pull request overview
This pull request fixes Devbox’s Nix version detection and comparison for newer Nix builds that omit the patch component (e.g. 2.33pre20251107_479b6b73), preventing Info.Version from being left empty and avoiding erroneous “Your version is .” guard failures.
Changes:
- Updated
versionRegexpto allow versions with onlymajor.minor(optional patch) while preserving existing prerelease/build parsing. - Refactored version comparison by adding
coerceSemver, including logic to insert a.0patch when missing before comparing withgolang.org/x/mod/semver. - Added unit tests covering parsing and
AtLeastbehavior for patchless prerelease versions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| nix/nix.go | Makes Nix version parsing accept patchless versions and coerces them into valid semver for comparisons. |
| nix/nix_test.go | Adds regression tests for parsing and AtLeast comparisons with patchless prerelease versions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
The one failing check ( The A re-run of the failed job should clear it (I don't have permission to trigger one via the API). Generated by Claude Code |
Summary
Fixes #2766.
Newer Nix releases report versions that omit the patch component, for example:
versionRegexp(used byparseInfo) required amajor.minor.patchtriple, so these versions failed to parse.Info.Versionwas then left empty, and the nix-version guard aborted every command with the confusing message:This made Devbox unusable on machines running recent
nixos-unstable/ nightly Nix builds.Fix
versionRegexp: make the patch component optional ((?:\.(?P<patch>…))?) so two-component versions like2.33pre20251107_479b6b73parse, while2.21.2continues to parse as before.Info.AtLeast: extract the version-coercion logic into a newcoerceSemverhelper and add amissingPatchRegexpthat inserts a zero patch (2.33pre…→2.33.0-pre.20251107+479b6b73) before comparison. This keeps the existing prerelease handling (2.23.0pre20240526_7de033d6) working and makes patchless versions comparable withgolang.org/x/mod/semver.How was it tested?
2.33pre20251107_479b6b73case toTestParseVersionInfoShort(parses to namenix, version2.33pre20251107_479b6b73).AtLeastassertions for the patchless prerelease version inTestVersionInfoAtLeast(>= 2.12.0,>= MinVersion,>= 2.33.0-pre.1,< 2.34.0).go test ./nix/andgo vet ./nix/pass. All pre-existing version tests (including the Lix2.90.0-beta.1and prerelease cases) still pass.cc @Electrenator (issue reporter)
Generated by Claude Code